var vm = new Vue({
    el: "#app",
    data:{
        countDown: '发送验证码', // 发送验证码按钮上的提示文字
        disabled: false, // 控制发送验证码按钮是否能够被点击，false可以被点击，true不能被点击
        ph_num:"",//手机号
        yanz:"",//验证码
        pwd:"",
        pwdtype:"password"
        
    },
    methods: {
        //显示密码
        select_pwd:function(){
            if(this.pwdtype=="password"){
                this.pwdtype="text"
            }else{
                this.pwdtype="text"
            }
        },
        // 点击头部的返回按钮，返回到上一个页面
        // 从哪里进来的，就返回到哪里
        back: function(){
            window.history.back();
        },

        // 点击确认按钮，提示用户找回密码成功
        confirmBtn: function(){
            if(vm.ph_num==""){
                app.alert("请输入手机号");
                return;
            }
            if(vm.yanz==""){
                app.alert("请输入验证码");
                return;
            }
            if(vm.pwd==""){
                app.alert("请输入密码");
                return;
            }
            if(vm.pwd.length<8){
                app.alert("请输入8位数以上密码");
                return;
            }
            var pwda = app.doublemd5(this.pwd);
            $.ajax({
                url:app.webUrl+"/member/api_user/forget",
                data:{pwd:pwda,mobile:vm.ph_num,sn:vm.yanz,},
                type:"GET",
                success:function(ret){
                //console.log(ret);
                    if(ret.code==1){
                        app.alert("修改成功");
                        setTimeout(function(){window.location.href = "./login.html"},1000);
                        
                    }else if(ret.code==0){
                        app.alert("修改失败");
                    }
                },
                error:function(err){
                    //console.log(err);
                }
            });
            // swal({
            //     title: "成功，请重新登录",
            //     timer: 800,
            //     button: false
            // }).then(function(){
            //     window.location.href='./login.html';
            // });
        },

        // 获取验证码
        getCheckCode:function(){
            this.send_code();
            this.disabled = true;
            var num = 59;
            this.countDown = 60;
            var that = this;
            var timer = setInterval(function(){
                that.countDown = num--;
                if(that.countDown == 0){
                    that.countDown = "发送验证码";
                    that.disabled = false;
                    clearInterval(timer);
                }
            }, 1000);
        },
        send_code: function () {
            send();
            console.log(vm.ph_num)
            function send() {
                $.ajax({
                    url: app.webUrl + '/index/plugin/execute/_plugin/Sms/_controller/Send/_action/SmsVeriSender.html',
                    data: {
                        mobile: vm.ph_num
                    },
                    type:'post',
                    success: cb
                })
            };
            function cb(ret) {
                console.log(ret);
                if (ret.code == '1') {
                    console.log(ret.msg)
                } else {
                }
            }
        },
    },
});